gdk: add gdk_window_create_similar_image_surface
authorAlexander Larsson <alexl@redhat.com>
Mon, 24 Jun 2013 10:10:02 +0000 (12:10 +0200)
committerAlexander Larsson <alexl@redhat.com>
Wed, 3 Jul 2013 12:34:13 +0000 (14:34 +0200)
This lets us create image surfaces that render faster on specific windows.
It also supports creating scaled image surfaces.

gdk/gdkwindow.c
gdk/gdkwindow.h

index 6943388e04393e4bff9fa4dd9ace5475845c0467..b69bdcda807c394e15525e5d9d35a93d333dd052 100644 (file)
@@ -9246,6 +9246,71 @@ gdk_window_create_similar_surface (GdkWindow *     window,
   return surface;
 }
 
+
+/**
+ * gdk_window_create_similar_image_surface:
+ * @window: window to make new surface similar to, or %NULL if none
+ * @format: (type int): the format for the new surface
+ * @width: width of the new surface
+ * @height: height of the new surface
+ * @scale: the scale of the new surface, or 0 to use same as @window
+ *
+ * Create a new image surface that is efficient to draw on the
+ * given @window.
+ *
+ * Initially the surface contents are all 0 (transparent if contents
+ * have transparency, black otherwise.)
+ *
+ * Returns: a pointer to the newly allocated surface. The caller
+ * owns the surface and should call cairo_surface_destroy() when done
+ * with it.
+ *
+ * This function always returns a valid pointer, but it will return a
+ * pointer to a "nil" surface if @other is already in an error state
+ * or any other error occurs.
+ *
+ * Since: 3.10
+ **/
+cairo_surface_t *
+gdk_window_create_similar_image_surface (GdkWindow *     window,
+                                        cairo_format_t  format,
+                                        int             width,
+                                        int             height,
+                                        int             scale)
+{
+  cairo_surface_t *window_surface, *surface;
+  GdkDisplay *display;
+  GdkScreen *screen;
+
+  g_return_val_if_fail (window ==NULL || GDK_IS_WINDOW (window), NULL);
+
+  if (window == NULL)
+    {
+      display = gdk_display_get_default ();
+      screen = gdk_display_get_default_screen (display);
+      window = gdk_screen_get_root_window (screen);
+    }
+
+  window_surface = gdk_window_ref_impl_surface (window);
+  if (scale == 0)
+    scale = gdk_window_get_scale_factor (window);
+
+  surface =
+    cairo_surface_create_similar_image (window_surface,
+                                       format,
+                                       width,
+                                       height);
+
+  cairo_surface_destroy (window_surface);
+
+#ifdef HAVE_CAIRO_SURFACE_SET_DEVICE_SCALE
+  cairo_surface_set_device_scale (surface, scale, scale);
+#endif
+
+  return surface;
+}
+
+
 /**
  * gdk_window_focus:
  * @window: a #GdkWindow
index 7840c6e0961fa429066e4291ca4d9e5c0fa4a7d9..0c394d8c4d42fb5258f471a1aaa84ee366d1753f 100644 (file)
@@ -911,6 +911,13 @@ cairo_surface_t *
                                           cairo_content_t  content,
                                           int              width,
                                           int              height);
+GDK_AVAILABLE_IN_3_10
+cairo_surface_t *
+              gdk_window_create_similar_image_surface (GdkWindow *window,
+                                                      cairo_format_t format,
+                                                      int            width,
+                                                      int            height,
+                                                      int            scale);
 
 GDK_AVAILABLE_IN_ALL
 void          gdk_window_beep            (GdkWindow       *window);